﻿
Partial Class DSEA
    Public Enum Tipo_Venta_Articulo As Integer
        Copa = 0
        Combinado = 1
        Refresco = 2
        Tapon = 3
        Botella = 5
        Gasto_Cocina = 6
        Cafes_Y_Otros = 7
    End Enum

    Public Enum Tipo_Articulo As Integer
        CafesYOtros = 1
        RefrescosYCervezas = 2
        CopasCombinados = 3
        VinosYMosto = 4
    End Enum

    Public Class Funciones_De_Validacion
        Inherits DSEATableAdapters.Funciones

        Public Shared Function F_Valida_Pin(ByVal strSocio As String, ByVal strPin As String) As Boolean
            Try
                Dim param As Global.MySql.Data.MySqlClient.MySqlParameter = New Global.MySql.Data.MySqlClient.MySqlParameter()
                Dim command = New Global.MySql.Data.MySqlClient.MySqlCommand

                command.CommandText = "Select F_Comprueba_Pass(@socio,@pin) "

                param = New Global.MySql.Data.MySqlClient.MySqlParameter()
                param.ParameterName = "@socio"
                param.DbType = Global.System.Data.DbType.String
                param.Size = 9
                param.IsNullable = True
                param.Value = strSocio
                command.Parameters.Add(param)

                param = New Global.MySql.Data.MySqlClient.MySqlParameter()
                param.ParameterName = "@pin"
                param.DbType = Global.System.Data.DbType.Int32
                param.Size = 4
                param.IsNullable = True
                param.Value = strPin
                command.Parameters.Add(param)

                Return CType(Lanza_Consultas(command), Boolean)

            Catch ex As Exception
                Return 0
            End Try
        End Function

        Public Shared Function F_Devuelve_Socio_Con_PIN(ByVal strPIN As String) As String
            Try
                Dim param As Global.MySql.Data.MySqlClient.MySqlParameter = New Global.MySql.Data.MySqlClient.MySqlParameter()
                Dim command = New Global.MySql.Data.MySqlClient.MySqlCommand

                command.CommandText = "Select Soc_ID From Tbl_Socios  Where Soc_PIN = @PIN"

                param = New Global.MySql.Data.MySqlClient.MySqlParameter()
                param.ParameterName = "@pin"
                param.DbType = Global.System.Data.DbType.Int32
                param.Size = 4
                param.IsNullable = True
                param.Value = strPIN
                command.Parameters.Add(param)

                Return CType(Lanza_Consultas(command), String)
            Catch ex As Exception
                Return ""
            End Try
        End Function

        Public Shared Function F_Devuelve_Grado_Socio(ByVal strSocio As String) As String
            Try
                Dim param As Global.MySql.Data.MySqlClient.MySqlParameter = New Global.MySql.Data.MySqlClient.MySqlParameter()
                Dim command = New Global.MySql.Data.MySqlClient.MySqlCommand

                command.CommandText = "Select Tbl_Tipo_Socios.TpSo_Denominacion  From Tbl_Socios  Inner Join " _
                                      + " Tbl_Tipo_Socios On Tbl_Socios.Soc_Per_ID = Tbl_Tipo_Socios.TpSo_ID" _
                                      + " Where Tbl_Socios.Soc_ID = @Socio"

                param = New Global.MySql.Data.MySqlClient.MySqlParameter()
                param.ParameterName = "@Socio"
                param.DbType = Global.System.Data.DbType.String
                param.Size = 9
                param.IsNullable = True
                param.Value = strSocio
                command.Parameters.Add(param)

                Return CType(Lanza_Consultas(command), String)
            Catch ex As Exception
                Return ""
            End Try
        End Function

        Private Shared Function Lanza_Consultas(ByVal Comando As Global.MySql.Data.MySqlClient.MySqlCommand) As Object
            Dim previousConnectionState As New Global.System.Data.ConnectionState

            Comando.Connection = New Global.MySql.Data.MySqlClient.MySqlConnection(Global.EguSoc_Dll.My.MySettings.Default.Conexion)
            Comando.CommandType = Global.System.Data.CommandType.Text

            If ((Comando.Connection.State And Global.System.Data.ConnectionState.Open) <> Global.System.Data.ConnectionState.Open) Then
                Comando.Connection.Open()
            End If

            Dim returnValue As Object
            Try
                returnValue = Comando.ExecuteScalar
            Finally
                If (previousConnectionState = Global.System.Data.ConnectionState.Closed) Then
                    Comando.Connection.Close()
                End If
            End Try
            If ((returnValue Is Nothing) OrElse (returnValue.GetType Is GetType(Global.System.DBNull))) Then
                Return 0
            Else
                Return CType(returnValue, Object)
            End If

        End Function
    End Class

    Friend Shared Function Devuelve_Fila_Anterior(ByVal DR As DataRow) As DataRow
        Try
            Dim DS As New DataSet
            Dim DT As New DataTable
            Dim FieldInfo As System.Reflection.FieldInfo = DR.GetType().GetField("_rowID", System.Reflection.BindingFlags.GetField Or _
                                                                                 System.Reflection.BindingFlags.GetProperty Or _
                                                                                 System.Reflection.BindingFlags.NonPublic Or _
                                                                                 System.Reflection.BindingFlags.Instance)
            Dim int As Integer = FieldInfo.GetValue(DR)
            DT = DR.Table.Copy

            DS.Tables.Add(DT)

            DS.Tables(DR.Table.ToString).Rows(int - 1).RejectChanges()

            Return DS.Tables(DR.Table.ToString).Rows(int - 1)
        Catch ex As Exception
            Return Nothing
        End Try
    End Function


End Class
